<template>
  <div id="all">
    <div class="left_nav" :class="{size_left_nav:flagSize}">
      <img v-if="!flagSize" class="logo" src="./common/images/headlogo.png" alt="">
      <img v-else class="logos" src="./common/images/headlogos.png" alt="">
      <ul class="left_nav_ul"  ref="nav_ul">
        <li @mouseover="hoverEvent(0)" @mouseout="outhoverEvent(0)" class="left_nav_li">
          <div @click="liHandle(0)" class="li_div">
            <img class="li_div_img" src="./common/images/left01.png" alt="">
            <transition name='flagSizeact'>
              <span v-show="!flagSize">主控台</span>
            </transition>
            <transition name='flagSizeact'>
              <div v-show="!flagSize" class="up_down">
                <img v-if="flag == 0" src="./common/images/left_down.png" alt="">
                <img v-else src="./common/images/left_up.png" alt="">
              </div>
            </transition>
          </div>
          <ul @click="ulHandle(0)" :class="[{size_left_nava:flagSize},{hover_handle:flagSize&&ifhover},{hover_handles:flagSize&&ifhovers}]" class="nav_list">
            <li><router-link to="/">工作台</router-link></li>
            <li><router-link to="/control/Overview">网站概况</router-link></li>
            <li><router-link to="/control/Column">栏目统计</router-link></li>
            <li><router-link to="/control/Product">产品统计</router-link></li>
            <li><router-link to="/control/article">文章统计</router-link></li>
          </ul>
        </li>
        <li @mouseover="hoverEvent(1)" @mouseout="outhoverEvent(1)" class="left_nav_li">
          <div @click="liHandle(1)" class="li_div">
            <img class="li_div_img" src="./common/images/left02.png" alt="">
            <transition name='flagSizeact'>
              <span v-show="!flagSize">信息管理</span>
            </transition>
            <transition name='flagSizeact'>
              <div v-show="!flagSize" class="up_down">
                <img v-if="flag == 1" src="./common/images/left_down.png" alt="">
                <img v-else src="./common/images/left_up.png" alt="">
              </div>
            </transition>
          </div>
          <ul @click="ulHandle(1)" :class="[{size_left_nava:flagSize},{hover_handle:flagSize&&ifhover},{hover_handles:flagSize&&ifhovers}]" class="nav_list">
            <li><router-link to="#">工作台</router-link></li>
            <li><router-link to="#">网站概况</router-link></li>
          </ul>
        </li>
        <li @mouseover="hoverEvent(2)" @mouseout="outhoverEvent(2)" class="left_nav_li">
          <div @click="liHandle(2)" class="li_div">
            <img class="li_div_img" src="./common/images/left03.png" alt="">
            <transition name='flagSizeact'>
              <span v-show="!flagSize">网站管理</span>
            </transition>
            <transition name='flagSizeact'>
              <div v-show="!flagSize" class="up_down">
                <img v-if="flag == 2" src="./common/images/left_down.png" alt="">
                <img v-else src="./common/images/left_up.png" alt="">
              </div>
            </transition>
          </div>
          <ul @click="ulHandle(2)" :class="[{size_left_nava:flagSize},{hover_handle:flagSize&&ifhover},{hover_handles:flagSize&&ifhovers}]" class="nav_list">
            <li><router-link to="#">工作台</router-link></li>
            <li><router-link to="#">网站概况</router-link></li>
            <li><router-link to="#">文章统计</router-link></li>
          </ul>
        </li>
        <li @mouseover="hoverEvent(3)" @mouseout="outhoverEvent(3)" class="left_nav_li">
          <div  @click="liHandle(3)" class="li_div">
            <img class="li_div_img" src="./common/images/left04.png" alt="">
            <transition name='flagSizeact'>
              <span v-show="!flagSize" >系统设置</span>
            </transition>
            <transition name='flagSizeact'>
              <div v-show="!flagSize" class="up_down">
                <img v-if="flag == 3" src="./common/images/left_down.png" alt="">
                <img v-else src="./common/images/left_up.png" alt="">
              </div>
            </transition>
          </div>
          <ul @click="ulHandle(3)" :class="[{size_left_nava:flagSize},{hover_handle:flagSize&&ifhover},{hover_handles:flagSize&&ifhovers}]" class="nav_list">
            <li><router-link to="#">工作台</router-link></li>
            <li><router-link to="#">网站概况</router-link></li>
            <li><router-link to="#">文章统计</router-link></li>
          </ul>
        </li>
        <li @mouseover="hoverEvent(4)" @mouseout="outhoverEvent(4)" class="left_nav_li">
          <div @click="liHandle(4)" class="li_div">
            <img class="li_div_img" src="./common/images/left05.png" alt="">
            <transition name='flagSizeact'>
              <span v-show="!flagSize" >网站模板</span>
            </transition>
            <transition name='flagSizeact'>
              <div v-show="!flagSize" class="up_down">
                <img v-if="flag == 4" src="./common/images/left_down.png" alt="">
                <img v-else src="./common/images/left_up.png" alt="">
              </div>
            </transition>
          </div>
          <ul @click="ulHandle(4)" :class="[{size_left_nava:flagSize},{hover_handle:flagSize&&ifhover},{hover_handles:flagSize&&ifhovers}]" class="nav_list">
            <li><router-link to="#">工作台</router-link></li>
            <li><router-link to="#">网站概况</router-link></li>
            <li><router-link to="#">文章统计</router-link></li>
          </ul>
        </li>
        <li @mouseover="hoverEvent(5)" @mouseout="outhoverEvent(5)" class="left_nav_li">
          <div @click="liHandle(5)" class="li_div">
            <img class="li_div_img" src="./common/images/left06.png" alt="">
            <transition name='flagSizeact'>
              <span v-show="!flagSize" >信息流</span>
            </transition>
            <transition name='flagSizeact'>
              <div v-show="!flagSize" class="up_down">
                <img v-if="flag == 5" src="./common/images/left_down.png" alt="">
                <img v-else src="./common/images/left_up.png" alt="">
              </div>
            </transition>
          </div>
          <ul @click="ulHandle(5)" :class="[{size_left_nava:flagSize},{hover_handle:flagSize&&ifhover},{hover_handles:flagSize&&ifhovers}]" class="nav_list">
            <li><router-link to="#">工作台</router-link></li>
            <li><router-link to="#">网站概况</router-link></li>
            <li><router-link to="#">文章统计</router-link></li>
          </ul>
        </li>
        <li @mouseover="hoverEvent(6)" @mouseout="outhoverEvent(6)" class="left_nav_li">
          <div @click="liHandle(6)" class="li_div">
            <img class="li_div_img" src="./common/images/left07.png" alt="">
            <transition name='flagSizeact'>
              <span v-show="!flagSize" >百度招聘</span>
            </transition>
            <transition name='flagSizeact'>
              <div v-show="!flagSize" class="up_down">
                <img v-if="flag == 6" src="./common/images/left_down.png" alt="">
                <img v-else src="./common/images/left_up.png" alt="">
              </div>
            </transition>
          </div>
          <ul @click="ulHandle(6)" :class="[{size_left_nava:flagSize},{hover_handle:flagSize&&ifhover},{hover_handles:flagSize&&ifhovers}]" class="nav_list">
            <li><router-link to="#">工作台</router-link></li>
            <li><router-link to="#">网站概况</router-link></li>
            <li><router-link to="#">文章统计</router-link></li>
          </ul>
        </li>
      </ul>
    </div>
    <div :class="{size_header_content:flagSize}" class="header_content">
      <div class="header">
        <img class="header_img" @click="sizeHandle" src="./common/images/head01.png" alt="">
        <div class="head_div">
          <img src="./common/images/seach.png" alt="">
          <img src="./common/images/kefu.png" alt="">
          <img src="./common/images/touxiang.png" alt="">
          <span>大明湖畔陈某人</span>
        </div>
      </div>
      <div class="content">
        <router-view></router-view>
      </div>
      <div class="footer">
        Copyright ©2018 baidujx.com
      </div>
    </div>
  </div>
</template>

<script>
import $ from 'jQuery'
import './common/js/all.js'
export default {
  data () {
    return {
      flag: 0,
      flagSize: false,
      flagSizeI: 0,
      ifhover: false,
      ifhovers: false
    }
  },
  methods: {
    liothers (idx) {
      // console.log(this.$refs.nav_ul.children[idx].children[1].style.height)
      for (var i = 0; i < this.$refs.nav_ul.childElementCount; i++) {
        if (i !== idx) {
          this.$refs.nav_ul.children[i].children[1].style.height = 0 + 'px'
        }
      }
    },
    liHandle (idx) {
      if (!this.flagSize) {
        var list = this.$refs.nav_ul.children[idx]
        if (this.flag !== idx) {
          this.flag = idx
          // console.log(this.flag)
          // console.log(this.$refs.nav_ul.children.filter(idx => idx != 0))
          list.children[1].style.height = list.children[1].children.length * list.children[1].children[1].clientHeight + 'px'
          this.liothers(idx)
        } else {
          this.flag = -1
          list.children[1].style.height = 0
        }
      }
    },
    liHandles (idx) {
      var list = this.$refs.nav_ul.children[idx]
      list.children[1].style.height = list.children[1].children.length * list.children[1].children[1].clientHeight + 'px'
      this.liothers(idx)
    },
    liliHandlex (idx) {
      var list = this.$refs.nav_ul.children[idx]
      list.children[1].style.height = 0
      $('.nav_list').css('transition', 'height .5s ease,width .1s ease .5s')
      // this.flag = -1
    },
    hoverEvent (idx) {
      if (this.flagSize) {
        this.ifhover = true
        this.ifhovers = true
        this.liHandles(idx)
      }
    },
    outhoverEvent (idx) {
      if (this.flagSize) {
        this.liliHandlex(idx)
        this.ifhover = false
      }
    },
    sizeHandle () {
      var idx = this.flag
      var list = this.$refs.nav_ul.children[idx]
      this.flagSize = !this.flagSize
      this.ifhover = false
      this.ifhovers = false
      console.log(this.flag)
      if (!this.flagSize && this.flag !== -1) {
        $('.nav_list').eq(idx).attr('style', 'height: 200px;')
        list.children[1].style.height = list.children[1].children.length * list.children[1].children[1].clientHeight + 'px'
      }
      if (!this.flagSize && this.flag == -1) {
        $('.nav_list').attr('style', 'height: 0px;')
      }
      if (this.flagSize && this.flag !== -1) {
        list.children[1].style.height = 0 + 'px'
      }
    },
    ulHandle (idx) {
      if (this.flagSize) {
        this.flag = idx
      }
    }
  },
  mounted () {
    var idx = this.flag
    var list = this.$refs.nav_ul.children[idx]
    list.children[1].style.height = list.children[1].children.length * list.children[1].children[1].clientHeight + 'px'
  }
}
</script>

<style>
  body,html{
    background-color: #f1f4f5;
  }
  .nav-enter,.nav-leave-to{
    height: 0;
  }
  .nav-enter-to,.nav-leave{
    height: auto;
  }
  .nav-enter-active,.nav-leave-active{
    transition: height .5s;
  }
  .flagSizeact-enter,.flagSizeact-leave-to{
    opacity: 0;
  }
  .flagSizeact-enter-to,.flagSizeact-leave{
    opacity: 1;
  }
  .flagSizeact-enter-active,.flagSizeact-leave-to{
    transition: opacity .5s ease;
  }
  #all{
    width: 100%;
    height: auto;
    min-width: 1910px;
    position: relative;
  }
  .header_content{
    width: calc(1920px - 256px);
    position: relative;
    float: right;
    transition: width .5s;
  }
  .left_nav{
    width: 256px;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    background-color: #001529;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    transition: width .5s;
    /* overflow: hidden; */
    z-index: 20;
  }
  .size_left_nav{
    width: 62px !important;
  }
  .size_left_nava{
    /* width: 62px !important; */
    /* transition: none !important; */
  }
  .header{
    width: 100%;
    /* padding: 0 27px; */
    height: 65px;
    /* position: absolute;
    top: 0;
    right: 0; */
    position: relative;
    background-color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
    z-index: 15;
  }
  .header img{
    cursor: pointer;
  }
  .head_div{
    /* width: 178px; */
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-right: 27px;
  }
  .head_div img{
    margin-right: 20px;
  }
  .head_div span{
    width: 100px;
    text-align: center;
    font-size: 14px;
    color: #333333;
  }
  .logo{
    width: 150px;
    height: 32px;
    margin: 15px auto 15px;
  }
  .logos{
    width: 32px;
    height: 32px;
    margin: 15px auto 15px;
  }
  .left_nav_ul{
    width: 100%;
    height: auto;
  }
  .left_nav_li{
    width: 100%;
    height: auto;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    position: relative;
  }
  .li_div{
    position: relative;
    width: 100%;
    height: 50px;
    cursor: pointer;
    display: flex;
    align-items: center;
    position: relative;
    /* margin: auto; */
  }
  .li_div span{
    font-size: 14px;
    color: #ffffff;
    margin-left: 21px;
    white-space: nowrap;
  }
  .up_down{
    width: 11px;
    height: 6px;
    position: absolute;
    right: 0;
    top: 50%;
    margin-top: -3.5px;
    display: flex;
    margin-right: 27px;
  }
  .nav_list{
    width: 100%;
    height: 0;
    background-color: #000c17;
    overflow: hidden;
    transition: height .5s ease,width .5s ease;
  }
  .nav_list li{
    width: 256px;
    height: 50px;
    /* padding-left:60px; */
    font-size: 14px;
    color: #ffffff;
    line-height: 50px;
  }
  .nav_list li:hover{
    background-color: #1890ff;
  }
  .nav_list li a{
    display: block;
    width: 196px;
    height: 100%;
    padding-left:60px;
    font-size: 14px;
    color: #ffffff;
    line-height: 50px;
  }
  .nav_height{
    height: auto;
  }
  .router-link-exact-active{
    background-color: #1890ff;
  }
  .size_header_content{
    width: calc(100% - 62px);
  }
  .content{
    width: 100%;
    /* margin-top: 65px; */
    min-height: 872px;
  }
  .header_img{
    margin-left: 27px;
  }
  .left_nav_li .hover_handle{
    width: 168px !important;
    transition: height .5s ease !important;
  }
  .hover_handles{
    position: absolute;
    right: -170px;
    top: 15px;
    z-index: 100;
    height: 200px;
    width: 62px !important;
  }
  .size_left_img{
    margin: auto;
  }
  .size_left_navs{
    width: 62px !important;
    padding-left: 21px;
  }
  .hover_p{
    width: 62px;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
  }
  .li_div_img{
    margin-left: 23px;
  }
  .footer{
    width: 100%;
    height: 100px;
    text-align: center;
    line-height: 100px;
    font-size: 14px;
  }
</style>
